package edu.whu.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.xpath.internal.operations.Bool;
import edu.whu.demo.dao.*;
import edu.whu.demo.domain.*;
import edu.whu.demo.exception.ScheduleAdminException;
import edu.whu.demo.service.IScheduleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2022-11-24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ScheduleServiceImpl extends ServiceImpl<ScheduleDao, Schedule> implements IScheduleService {


    @Autowired
    ActivityDao activityDao;
    @Autowired
    ScheduleDetailDao scheduleDetailDao;

    @Autowired
    ScheduleViewDao scheduleViewDao;

    @Autowired
    EntryDao entryDao;

    @Autowired
    MessageServiceImpl messageService;

    @Autowired
    MessageDao messageDao;
    /*创建日程*/
    @Override
    public Schedule createSchedule(Schedule schedule) throws ScheduleAdminException {

        try {
            this.baseMapper.insert(schedule);
            createScheduleDetailFrequency(schedule);
            return schedule;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new ScheduleAdminException("新建日程失败！");
        }
    }


    public void createScheduleDetailOnce(String beginDate, String endDate,Schedule schedule , Integer frequencyCount, String time1, String time2) throws ScheduleAdminException {
        try{DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter df2 = DateTimeFormatter.ofPattern("HH:mm:ss");
        List<String> betweenDate = getBetweenDate(beginDate,endDate);
        ScheduleDetail detail = new ScheduleDetail();
        for (int i = 0; i < betweenDate.size(); i++) {
            detail.setDate(betweenDate.get(i));
            if(time1.equals("时间待定")){
                detail.setBeginTime(time1);
            }else{
                detail.setBeginTime("00:00:00");
            }
            if(time2.equals("时间待定")){
                detail.setEndTime(time2);
            }else{
                detail.setEndTime("24:00:00");
            }
            if(i==0){
                detail.setBeginTime(time1);
            }
            if(i==(betweenDate.size()-1)){
                detail.setEndTime(time2);
            }
            detail.setFrenquencyCount(frequencyCount);
            detail.setScheduleId(schedule.getId());
            detail.setRemind(schedule.getRemind());
            scheduleDetailDao.insert(detail);
            if(!detail.getDate().equals("日期待定")&&schedule.getRemind()!=null){
                if(!schedule.getRemind().equals("不提醒")){
                    String remind = schedule.getRemind();
                    long addTimes = 0L;
                    switch (remind){
                        case "日程开始时":addTimes=0L;
                        break;
                        case "15分钟前":addTimes=15L;
                        break;
                        case "30分钟前":addTimes=30L;
                        break;
                        case "一个小时前":addTimes=60L;
                        break;
                    }
                    String time = detail.getBeginTime();
                    if(detail.getEndTime().equals("时间待定")){
                        time="00:00:00";
                    }
                    String contenet ="注意日程:"+schedule.getTitle()+" 即将开始！";
                    Message m = new Message();
                    m.setToUid(schedule.getUid());
                    m.setType("schedule");
                    m.setIsRead(0);
                    String date = detail.getDate();
                    String localTimeString = date+" "+time;
                    LocalDateTime localTime = LocalDateTime.parse(localTimeString,df);
                    localTime=localTime.minusMinutes(addTimes);
                    m.setTime(localTime);
                    m.setContent(contenet);
                    m.setFromUid(detail.getId());
                    messageService.addMessage(m);
                }
            }
        }
        }catch (Exception ex){
            throw new ScheduleAdminException("新建日程失败"+ex.getMessage());
        }
    }

    public void createScheduleDetailFrequency(Schedule schedule) throws ScheduleAdminException {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter df2 = DateTimeFormatter.ofPattern("HH:mm:ss");
        String beginTimeString = schedule.getBeginTime();
        String endTimeString = schedule.getEndTime();
        LocalDateTime beginTime = LocalDateTime.now();
        LocalDateTime endTime = LocalDateTime.now();
        String beginDate = beginTime.format(df1);
        String endDate=endTime.format(df1);
        String time1 = beginTime.format(df2);
        String time2 = endTime.format(df2);
        if(beginTimeString.length()>=10&&endTimeString.length()>=10){
            if(beginTimeString.length()==10){
                beginTime = LocalDateTime.parse(beginTimeString+" 00:00:00",df);
                beginDate = beginTimeString;
                time1="时间待定";
            }else{
                beginTime = LocalDateTime.parse(beginTimeString, df);
                beginDate = beginTime.format(df1);
                time1 = beginTime.format(df2);
            }
            if(endTimeString.length()==10){
                endTime = LocalDateTime.parse(endTimeString+" 00:00:00",df);
                endDate = endTimeString;
                time2="时间待定";
            }else{
                endTime = LocalDateTime.parse(endTimeString, df);
                endDate = endTime.format(df1);
                time2 = endTime.format(df2);
            }
        }
        if(beginTimeString.length()>=10&&endTimeString.length()<5){//只有开始时间
            if(beginTimeString.length()==10){
                beginTime = LocalDateTime.parse(beginTimeString+" 00:00:00",df);
                beginDate = beginTimeString;
                time1="时间待定";
            }else{
                beginTime = LocalDateTime.parse(beginTimeString, df);
                beginDate = beginTime.format(df1);
                time1 = beginTime.format(df2);
            }
            endDate = beginDate;
            endTimeString = endDate+" 00:00:00";
            endTime = LocalDateTime.parse(endTimeString,df);
            time2 = "时间待定";
        }
        if(beginTimeString.length()<5&&endTimeString.length()>=10){//只有结束时间
            if(endTimeString.length()==10){
                endTime = LocalDateTime.parse(endTimeString+" 00:00:00",df);
                endDate = endTimeString;
                time2="时间待定";
            }else{
                endTime = LocalDateTime.parse(endTimeString, df);
                endDate = endTime.format(df1);
                time2 = endTime.format(df2);
            }
            beginDate = endDate;
            beginTimeString = beginDate+" 00:00:00";
            beginTime = LocalDateTime.parse(beginTimeString,df);
            time1 = "时间待定";
        }if(beginTimeString.length()<5&&endTimeString.length()<5){//没有开始时间也没有结束时间----时间待定
            ScheduleDetail detail = new ScheduleDetail();
            detail.setDate("日期待定");
            detail.setBeginTime("时间待定");
            detail.setEndTime("时间待定");
            detail.setScheduleId(schedule.getId());
            detail.setFrenquencyCount(0);
            scheduleDetailDao.insert(detail);
            return;
        }
        int count = 0;
        createScheduleDetailOnce(beginDate,endDate,schedule,count,time1,time2);
        String frequency = schedule.getFrequency();
        String repeatEndTime = schedule.getRepeatEndTime();
        repeatEndTime = repeatEndTime+" 00:00:00";
        if(frequency!=null&&frequency.length()==3&&!schedule.getLabel().equals("活动日程")){
            int num = Integer.valueOf(frequency.substring(1,2));
            String unit = frequency.substring(2,3);
            System.out.println((beginTime.isBefore(LocalDateTime.parse(repeatEndTime, df))));
            System.out.println(schedule.getRepeatEndTime() != null);
            System.out.println(schedule.getRepeatEndTime().length());
            if(unit.equals("天")){
                beginTime=beginTime.plusDays(num);
                endTime=endTime.plusDays(num);
            }if(unit.equals("周")){
                beginTime=beginTime.plusWeeks(num);
                endTime=endTime.plusWeeks(num);

            }if(unit.equals("月")){
                beginTime=beginTime.plusMonths(num);
                endTime=endTime.plusMonths(num);

            }if(unit.equals("年")){
                beginTime= beginTime.plusYears(num);
                endTime=endTime.plusYears(num);
            }
            while((beginTime.isBefore(LocalDateTime.parse(repeatEndTime,df)))&&schedule.getRepeatEndTime()!=null&&schedule.getRepeatEndTime().length()==10){
                beginDate = beginTime.format(df1);
                endDate = endTime.format(df1);
                count++;
                createScheduleDetailOnce(beginDate,endDate,schedule,count,time1,time2);
                if(unit.equals("天")){
                    beginTime=beginTime.plusDays(num);
                    endTime=endTime.plusDays(num);
                }if(unit.equals("周")){
                    beginTime=beginTime.plusWeeks(num);
                    endTime=endTime.plusWeeks(num);
                }if(unit.equals("月")){
                    beginTime=beginTime.plusMonths(num);
                    endTime=endTime.plusMonths(num);
                }if(unit.equals("年")){
                   beginTime= beginTime.plusYears(num);
                   endTime=endTime.plusYears(num);
                }
        }
        }
    }
    /*获取两个日期之间的所有日期*/
    public static List<String> getBetweenDate(String startTime, String endTime) throws ScheduleAdminException {
        try{SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 声明保存日期集合
        List<String> list = new ArrayList<>();
        // 转化成日期类型
        Date startDate = sdf.parse(startTime);
        Date endDate = sdf.parse(endTime);

        //用Calendar 进行日期比较判断
        Calendar calendar = Calendar.getInstance();
        while (startDate.getTime()<=endDate.getTime()){
            // 把日期添加到集合
            list.add(sdf.format(startDate));
            // 设置日期
            calendar.setTime(startDate);
            //把日期增加一天
            calendar.add(Calendar.DATE, 1);
            // 获取增加后的日期
            startDate=calendar.getTime();
        }
        return list;
        }catch (Exception ex){
            throw new ScheduleAdminException("获取两个日期之间的所有日期失败"+ex.getMessage());
        }

    }

    @Override
    public Schedule getScheduleById(long id) {
        Schedule schedule = this.baseMapper.selectById(id);
        if(schedule.getActivityId()!=null){
            /*更新schedule*/
            Activity activity = activityDao.selectById(schedule.getActivityId());
            schedule.setTitle(activity.getName());
            schedule.setBeginTime(activity.getBeginTime());
            schedule.setEndTime(activity.getEndTime());
            schedule.setLocation(activity.getPlace());
            this.baseMapper.updateById(schedule);
            return schedule;
        }else{
            return schedule;
        }
    }

    @Override
    public List<String> divideTime(String time){
        String[] r = time.split("，");
        int count = charCount(time,"，");
        System.out.println(count);
        List<String> result = new ArrayList<>();
        for (int i = 0; i < r.length; i++) {
            result.add(r[i]);
        }
        return result;
    }

    /*查找字符串str有多少个s*/
    public int charCount(String s,String str){
        int count = 0,len = str.length();
        while(str.indexOf(s) != -1) {
            str = str.substring(str.indexOf(s) + 1,str.length());
            count++;
        }
        return count;
    }
    /*将活动加入日程*/
    /*活动日程的剩余信息，用户可以更新*/
    /*当爬虫更新数据库时，日程也跟着变化*/
    @Override
    public Schedule addSchedule(long uid,long activityId) throws ScheduleAdminException {
        QueryWrapper<Schedule> qw=new QueryWrapper<>();
        qw.eq("uid",uid);
        qw.eq("activity_id",activityId);
        List<Schedule> li = this.baseMapper.selectList(qw);
        if(li.size()>0){
            throw new ScheduleAdminException("用户多次加入同一活动进入日程");
        }
        try {
            // entry：加入我的活动
            Entry entry = new Entry();
            entry.setUid(uid);
            entry.setActivityId(activityId);
            entryDao.insert(entry);

            Activity activity = activityDao.selectById(activityId);
            String beginTime = activity.getBeginTime();
            String endTime = activity.getEndTime();
            List<String> beginTimeList = divideTime(beginTime);
            List<String> endTimeList = divideTime(endTime);
            Long id = Long.valueOf(0);
            Schedule schedule = new Schedule();
            schedule.setUid(uid);
            schedule.setTitle(activity.getName());
            schedule.setLabel("活动日程");
            schedule.setLocation(activity.getPlace());
            schedule.setActivityId(activityId);
            for (int i = 0; i < beginTimeList.size(); i++) {
                schedule.setBeginTime(beginTimeList.get(i));
                schedule.setEndTime(endTimeList.get(i));
                createSchedule(schedule);
            }
            id = schedule.getId();
            Integer times = activity.getAddedTimes();
            System.out.println(times);
            if(times==null){
                times = 1;
            }else{
                times = times + 1;
            }
            activity.setAddedTimes(times);
            activityDao.updateById(activity);
            return this.baseMapper.selectById(id);
        }catch (Exception ex) {
            throw new ScheduleAdminException("将活动加入日程失败！"+ex.getMessage());
        }
    }

    /*uid是发起更新日程的操作者，比如说活动发布者hostUid，或者日程持有者uid*/
    @Override
    public Schedule updateScheduleUser(long uid,long id, Schedule schedule) throws ScheduleAdminException{
        if (this.baseMapper.selectById(schedule.getId()) == null || id != schedule.getId()) {
            /*对应日程不存在*/
            throw new ScheduleAdminException("对应日程不存在");
        }
        try {
            Schedule beforeSchedule = this.baseMapper.selectById(id);
            Long activityId = beforeSchedule.getActivityId();
            /*查找对应活动负责人*/
            if (activityId != null) {
                Activity activity = activityDao.selectById(activityId);
                if (activity.getHostUid() == uid) {
                    /*更新日程的人是活动的发布者*/
                    /*只允许更改title、begintime、endtime、location、activityState*/
                    /*label是定死是“活动日程”，所以不能改*/
                    if (schedule.getLabel().equals("活动日程")) {
                        LambdaUpdateWrapper<Schedule> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
                        lambdaUpdateWrapper.eq(Schedule::getActivityId, schedule.getActivityId())
                                .set(Schedule::getTitle, schedule.getTitle())
                                .set(Schedule::getBeginTime, schedule.getBeginTime())
                                .set(Schedule::getEndTime, schedule.getEndTime())
                                .set(Schedule::getLocation, schedule.getLocation());
                        this.baseMapper.update(null, lambdaUpdateWrapper);
                        QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
                        dwq.eq("schedule_id",schedule.getId());
                        List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
                        for (int i = 0; i < details.size(); i++) {
                            messageDao.deleteMessageByScheduleDetail(details.get(i).getId());
                        }
                        scheduleDetailDao.deleteScheduleDetailBySchedule(schedule.getId());

                        createScheduleDetailFrequency(schedule);
                        return this.baseMapper.selectById(id);
                    } else {
                        throw new ScheduleAdminException("活动发起者不能更改用户的除标签为“活动日程”以外的个人日程");
                    }
                } else if (uid == schedule.getUid()) {
                    if (schedule.getLabel().equals("活动日程")) {
                        LambdaUpdateWrapper<Schedule> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
                        lambdaUpdateWrapper.eq(Schedule::getUid, schedule.getUid())
                                .set(Schedule::getRemind, schedule.getRemind())
                                .set(Schedule::getMemo, schedule.getMemo());
                        this.baseMapper.update(null, lambdaUpdateWrapper);
                        QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
                        dwq.eq("schedule_id",schedule.getId());
                        List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
                        for (int i = 0; i < details.size(); i++) {
                            messageDao.deleteMessageByScheduleDetail(details.get(i).getId());
                        }
                        scheduleDetailDao.deleteScheduleDetailBySchedule(schedule.getId());

                        createScheduleDetailFrequency(schedule);
                        return this.baseMapper.selectById(id);
                    }
                }
            }
            /*更新日程的人是用户自己*/
            /*一般用户不可以更改活动日程的title、time、label、location、activityId、frequency、repeatEndTime*/
            else if (uid == schedule.getUid()) {
                if (schedule.getLabel().equals("活动日程")) {
                    LambdaUpdateWrapper<Schedule> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
                    lambdaUpdateWrapper.eq(Schedule::getUid, schedule.getUid())
                            .set(Schedule::getRemind, schedule.getRemind())
                            .set(Schedule::getMemo, schedule.getMemo());
                    this.baseMapper.update(null, lambdaUpdateWrapper);
                    QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
                    dwq.eq("schedule_id",schedule.getId());
                    List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
                    for (int i = 0; i < details.size(); i++) {
                        messageDao.deleteMessageByScheduleDetail(details.get(i).getId());
                    }
                    scheduleDetailDao.deleteScheduleDetailBySchedule(schedule.getId());

                    createScheduleDetailFrequency(schedule);

                    return this.baseMapper.selectById(id);
                } else {
                    this.baseMapper.updateById(schedule);
                    QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
                    dwq.eq("schedule_id",schedule.getId());
                    List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
                    for (int i = 0; i < details.size(); i++) {
                        messageDao.deleteMessageByScheduleDetail(details.get(i).getId());
                    }
                    scheduleDetailDao.deleteScheduleDetailBySchedule(schedule.getId());

                    createScheduleDetailFrequency(schedule);
                    return this.baseMapper.selectById(id);
                }
            }
            throw new ScheduleAdminException("更新日程失败，非活动发布者不能更改其他用户的日程");
        }catch (Exception ex){
            throw new ScheduleAdminException("更新日程失败"+ex.getMessage());
        }
    }


    /*活动更新日程*/
    @Override
    public void updateSchedule(long activityId) throws ScheduleAdminException {
        try {
            Activity activity = activityDao.selectById(activityId);
            List<Schedule> updateList = this.baseMapper.findScheduleByActivityId(activityId);
            String beginTime = activity.getBeginTime();
            String endTime = activity.getEndTime();
            List<String> beginTimeList = divideTime(beginTime);
            List<String> endTimeList = divideTime(endTime);
            if(updateList.size()==beginTimeList.size()){
                for (int i = 0; i < updateList.size(); i++) {
                    updateList.get(i).setTitle(activity.getName());
                    updateList.get(i).setLabel("活动日程");
                    updateList.get(i).setLocation(activity.getPlace());
                    updateList.get(i).setActivityId(activityId);
                    updateList.get(i).setBeginTime(beginTimeList.get(i));
                    updateList.get(i).setEndTime(endTimeList.get(i));
                    this.baseMapper.updateById(updateList.get(i));
                    QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
                    dwq.eq("schedule_id",updateList.get(i).getId());
                    List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
                    for (int j = 0; j < details.size(); j++) {
                        messageDao.deleteMessageByScheduleDetail(details.get(j).getId());
                    }
                    scheduleDetailDao.deleteScheduleDetailBySchedule(updateList.get(i).getId());

                    createScheduleDetailFrequency(updateList.get(i));
                }
            }
        } catch (Exception ex) {
            throw new ScheduleAdminException("更新日程失败"+ex.getMessage());
        }
    }

    @Override
    public void deleteSchedule(long id) {
        QueryWrapper<ScheduleDetail> dwq = new QueryWrapper<>();
        dwq.eq("schedule_id",id);
        List<ScheduleDetail> details = scheduleDetailDao.selectList(dwq);
        for (int j = 0; j < details.size(); j++) {
            messageDao.deleteMessageByScheduleDetail(details.get(j).getId());
        }
        scheduleDetailDao.deleteScheduleDetailBySchedule(id);

        this.baseMapper.deleteById(id);
    }


     @Override
    public IPage<ScheduleView> findScheduleDetails(Map<String, Object> condition, long pageNum, long pageSize) throws ScheduleAdminException {
         IPage<ScheduleView> page = new Page<>(pageNum,pageSize);
         //关键字、日期、标签、活动id
         if(!condition.containsKey("uid")){
             throw new ScheduleAdminException("用户不存在");
         }
         QueryWrapper<ScheduleView> qw = new QueryWrapper<>();
         qw.eq(condition.containsKey("uid"),"sv.uid",condition.get("uid"));
         if(condition.containsKey("keyword")){
             qw.and((wrap) -> {
                 wrap.like(condition.containsKey("keyword"), "sv.title", condition.get("keyword")).
                         or().like(condition.containsKey("keyword"), "sv.location", condition.get("keyword")).
                         or().like(condition.containsKey("keyword"), "sv.date", condition.get("keyword")).
                         or().like(condition.containsKey("keyword"), "sv.label", condition.get("keyword")).
                         or().like(condition.containsKey("keyword"),"sv.memo",condition.get("keyword"));
             });
             qw.orderBy(true,true,"sv.date,sv.begin_time,sv.end_time");
             scheduleViewDao.findScheduleView(page,qw);
         }else{
             qw.eq(condition.containsKey("uid"),"sv.uid",condition.get("uid"));
             qw.like(condition.containsKey("date"),"sv.date",condition.get("date"));
             qw.like(condition.containsKey("label"),"sv.label",condition.get("label"));
             qw.eq(condition.containsKey("activityId"),"sv.activity_id",condition.get("activityId"));
             qw.orderBy(true,true,"sv.date,sv.begin_time,sv.end_time");
             scheduleViewDao.findScheduleView(page,qw);
         }
         return page;
    }

    @Override
    public List<String> findScheduleLabel(){
         List<Schedule> scheduleList = this.baseMapper.findScheduleLabel();
         List<String> res=new ArrayList<>();
        for (int i = 0; i < scheduleList.size(); i++) {
            res.add(scheduleList.get(i).getLabel());
        }
        return res;
    }

    /*根据当前日期获取当前一周的所有日期*/
   @Override
    public List<String> getWeekDays(String date1) throws ScheduleAdminException {
        try{SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        Calendar cal = Calendar.getInstance();
       Date date = null;
       date = sdf.parse(date1);
       cal.setTime(date);
        // 获得当前日期是一个星期的第几天
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        // 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        // 获得当前日期是一个星期的第几天
        int day = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
        list.add(sdf.format(cal.getTime()));
        for (int i = 1; i < 7; i++) {
            cal.add(Calendar.DAY_OF_MONTH, 1);
            list.add(sdf.format(cal.getTime()));
        }
        return list;
        }catch (Exception ex){
            throw new ScheduleAdminException("获取当前一周的所有日期失败"+ex.getMessage());
        }
    }

    @Override
    public Map<String, List<ScheduleView>> getWeekSchedule(Long uid,String date) throws ScheduleAdminException{
       try {
           List<String> weekList = null;
           weekList = getWeekDays(date);
           Map<String, List<ScheduleView>> result = new HashMap<>();
           int week = 0;
           for (String week1 : weekList) {
               QueryWrapper<ScheduleView> qw = new QueryWrapper<>();
               qw.eq("uid", uid);
               qw.eq("date", week1);
               qw.orderBy(true, true, "date");
               List<ScheduleView> weekSchedule = scheduleViewDao.selectList(qw);
               result.put(String.valueOf(week), weekSchedule);
               week++;
           }
           return result;
       }catch (Exception ex){
           throw new ScheduleAdminException("获取一周日程失败"+ex.getMessage());
       }
    }
}
